package com.demo.third;

import com.alibaba.fastjson.JSONObject;
import com.github.binarywang.demo.wx.cp.aes.HttpUt;
import com.github.binarywang.demo.wx.cp.controller.ThirdBaseController;
import org.w3c.dom.Attr;

/**
 * created by lanxinghua@2dfire.com on 2020/2/15
 * 第三方应用开发：外部联系人管理
 *
 */
public class ThirdExtCustomerDemo extends ThirdBaseController {

    public static void main(String[] args) throws Exception{
        // listExternalContact(getAccessToken(true), "lanxinghua@2dfire.com");
        // getExternalContactDetail(getAccessToken(true),"wm6pcPDQAAVbNEqigOywtU9CmtTz7EfA");
    }

    /**
     * 获取客户列表
     * @param accessToken
     * @param userId
     * @throws Exception
     *
     * 结果：{"errcode":0,"external_userid":["wm6pcPDQAAVbNEqigOywtU9CmtTz7EfA","wm6pcPDQAAwr-8kxGbjGbemr9qVnAajg"],"errmsg":"ok"}
     */
    public static void listExternalContact(String accessToken, String userId) throws Exception{
        String url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list?access_token=%s&userid=%s";
        JSONObject result = HttpUt.sendGet(String.format(url, accessToken, userId));
        System.out.println("客户列表："+result.toJSONString());
    }


    /**
     * 获取客户详情
     * @param accessToken
     * @param external_userid
     * @throws Exception
     *
     * {
     *     "errcode":0,
     *     "follow_user":[
     *         {
     *             "createtime":1581765991,
     *             "remark_mobiles":[
     *             ],
     *             "description":"",
     *             "remark":"",
     *             "userid":"linghua@ie.com",
     *             "tags":[
     *
     *             ]
     *         }
     *     ],
     *     "errmsg":"ok",
     *     "external_contact":{
     *         "external_userid":"wm6pcPDQAAVbNEqigOywtU9CmtTz7EfA",
     *         "gender":1,
     *         "name":"蓝花",
     *         "type":1
     *     }
     * }
     */
    public static void getExternalContactDetail(String accessToken, String external_userid) throws Exception{
        String url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?access_token=%s&external_userid=%s";
        JSONObject result = HttpUt.sendGet(String.format(url, accessToken, external_userid));
        System.out.println("客户详情："+result.toJSONString());
    }
}
